package com.github.slprj.slake.net;

import com.github.slprj.slake.common.SlTime;

import java.util.concurrent.CompletableFuture;

/**
 * @author YangXiaoLong
 * @date 2022/8/26 17:43
 */
public class WriteData {
    private final SlChannel slc;
    private final Peer peer;
    private final WriteFrame data;
    private final SlTime timeout;
    /**
     * future主要是完成数据请求,返回结果,用于下面几种场景下
     * -请求超时,异常
     * -消息重发异常
     * -消息串改异常
     * -解码异常
     * -返回正确数据
     */
    private final CompletableFuture<ReadFrame> future;
    private final Decoder decoder;

    /**
     * 客户端发送消息,载体 WriteData,向哪个通道写入,写入的数据是什么,过期时间为多久,用什么来解码
     */
    public WriteData(Peer peer, WriteFrame data, SlTime timeout,
                     CompletableFuture<ReadFrame> future, Decoder decoder) {
        this.peer = peer;
        this.slc = null;
        this.data = data;
        this.timeout = timeout;
        this.future = future;
        this.decoder = decoder;
    }

    public WriteData(SlChannel dtc, WriteFrame data) {
        this.slc = dtc;
        this.peer = null;
        this.data = data;
        this.timeout = null;
        this.future = null;
        this.decoder = null;
    }

    public SlChannel getSlc() {
        return slc;
    }


    public SlTime getTimeout() {
        return timeout;
    }

    public CompletableFuture<ReadFrame> getFuture() {
        return future;
    }

    public WriteFrame getData() {
        return data;
    }

    public Decoder getDecoder() {
        return decoder;
    }

    public Peer getPeer() {
        return peer;
    }
}
